package com.jf.ai.etl.reader;

import org.springframework.ai.document.Document;
import org.springframework.ai.reader.TextReader;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2025-07-19
 * Time:18:14
 */
@Component
public class JfTextReader {
    private final Resource resource;
    public JfTextReader(@Value("classpath:bike.txt") Resource resource) {
        this.resource = resource;
    }
    public List<Document> loadText() {
        TextReader textReader = new TextReader(resource);
        textReader.setCharset(StandardCharsets.UTF_8);
        textReader.getCustomMetadata().put("tag", "bike");

        return textReader.get();
    }
}
